package com.bstek.demo.service;

import com.bstek.urule.model.ExposeAction;
import com.bstek.urule.model.library.action.annotation.ActionBean;
import com.bstek.urule.model.library.action.annotation.ActionMethod;
import com.bstek.urule.model.library.action.annotation.ActionMethodParameter;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

/**
 * 自定义动作库
 */
@Component("myAction")
@ActionBean(name="自定义内置动作")
public class MyAction{

    @ExposeAction("截取字符串")
    public String substring(String str,int start,int end){
        return str.substring(start, end);
    }

    @ExposeAction("判断字符串是不是数字")
    public  boolean isNumber(String str){
       return NumberUtils.isNumber(str);
    }




    @ExposeAction("月份转集合")
    @ActionMethod(name="月份转集合")
    @ActionMethodParameter(names={"目标对象"})
    public ArrayList monList(Object mon){
        if (mon!=null){
            Integer index = Integer.valueOf(mon + "");
            ArrayList<Object> list = new ArrayList<>();
            for (int i = 1; i <=index; i++) {
                list.add(i);
            }
            return list;
        }
        return null;
    }
}
